package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.ZTreeNode;
import com.isunland.managesystem.utils.LogUtil;
import java.util.ArrayList;
import java.util.HashMap;

public class DistrictDialogFragment extends BaseNetworkDialogFragment {

  private CurrentUser mCurrentUser;
  private String mMemberCode;

  @Override public void onCreate(Bundle savedInstanceState) {
    mCurrentUser = CurrentUser.newInstance(getActivity());
    mMemberCode = mCurrentUser.getMemberCode();
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {

      ZTreeNode[] customerContacts = new Gson().fromJson(arg0, ZTreeNode[].class);

      if (customerContacts == null || customerContacts.length == 0) {

        return list;
      }

      for (int i = 0; i < customerContacts.length; i++) {
        list.add(new CustomerDialog(customerContacts[i].getName(),
            customerContacts[i].getExtParam() + ""));
      }
    } catch (Exception e) {
      LogUtil.e(TAG, "Exception", e);
    }

    return list;
  }

  @Override public String getUrl() {

    return ApiConst.URL_DISTRICT;
  }

  @Override public HashMap<String, String> getparameters() {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("android", "true");
    params.put("memberCode", mMemberCode);
    //memberCode:"memberCode"
    return params;
  }
}
